package com.qingcloud.fexecutor.controller;

import com.qingcloud.fexecutor.base.enums.DataSourceEnum;
import com.qingcloud.fexecutor.base.pojo.WebPageDataParam;
import com.qingcloud.fexecutor.service.WebPageDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api(value = "页面数据相关接口", tags = "页面数据相关接口")
@RestController
@RequestMapping("/webdata")
public class WebDataController {

    @Resource
    private WebPageDataService webPageDataService;

    @ApiOperation(value = "数据源资源执行统一入口", notes = "数据源资源执行统一入口")
    @PostMapping("/datasource/execute")
    public Object sqlExecute(@RequestBody WebPageDataParam.PageParam pageParam,
                             @RequestHeader(value = "appUrl", required = false) String appUrl) throws Exception {
        if (DataSourceEnum.REDIS.code.equals(pageParam.getDatasourceType())) {
            //redis数据源
            return webPageDataService.redisExecute(pageParam);

        }
        return webPageDataService.sqlExecute(pageParam.getPageId(), pageParam.getResourceCode(), pageParam.getPage(),
                pageParam.getPageSize(), pageParam.getJson(), pageParam.getSql(), pageParam.getViewType());
    }

}
